package com.ytf.test.tenth;

/**
 * @author: YTF
 * @date: 2025/3/27
 * @version: 1.0
 * @description:
 */
interface Service{
    void method1();
    void method2();
}
interface ServiceFactory{
    Service getService();
}
class Implementation1 implements ServiceFactory{


    @Override
    public Service getService() {
        return new Service() {
            @Override
            public void method1() {
                System.out.println("Implementation1 method1");
            }

            @Override
            public void method2() {
                System.out.println("Implementation1 method2");
            }
        };
    }
}
class Implementation2 implements ServiceFactory{

    @Override
    public Service getService() {
        return new Service() {
            @Override
            public void method1() {
                System.out.println("Implementation2 method1");
            }

            @Override
            public void method2() {
                System.out.println("Implementation2 method2");
            }
        };
    }
}
class Implementation3 implements Service{
    private Implementation3() {
    }
    @Override
    public void method1() {
        System.out.println("Implementation3 method1");
    }

    @Override
    public void method2() {
        System.out.println("Implementation3 method2");
    }
    public static ServiceFactory sf = new ServiceFactory() {
        @Override
        public Service getService() {
            return new Implementation3();
        }
    };
}
class Implementation4 implements Service{

    @Override
    public void method1() {
        System.out.println("Implementation4 method1");
    }

    @Override
    public void method2() {
        System.out.println("Implementation4 method2");
    }
    public static ServiceFactory sf = () -> new Implementation4();
}
public class Factories {
    public static Service getService(ServiceFactory serviceFactory) {
        return serviceFactory.getService();
    }
    public static void main(String[] args) {
        Service service1 = getService(new Implementation1());
        service1.method1();
        service1.method2();
        Service service2 = getService(new Implementation2());
        service2.method1();
        service2.method2();

        Service service3 = getService(Implementation3.sf);
        service3.method1();
        service3.method2();
        Service service4 = getService(Implementation4.sf);
        service4.method1();
        service4.method2();
        /**
         * Output:
         * Implementation1 method1
         * Implementation1 method2
         * Implementation2 method1
         * Implementation2 method2
         * Implementation3 method1
         * Implementation3 method2
         * Implementation4 method1
         * Implementation4 method2
         */
    }
}
